import axios from 'axios';
import type { RouteRecordNormalized } from 'vue-router';
import { UserState } from '@/store/modules/user/types';

export interface LoginData {
  username: string;
  password: string;
}

export interface LoginRes {
  token: string;
}
export function login(data: LoginData) {
  return axios.post<LoginRes>('/user/login', data);
}

export function logout() {
  return axios.post<LoginRes>('/api/user/logout');
}

export function getUserInfo() {
  return axios.post<UserState>('/user/info');
}

export function getMenuList() {
  return axios.post<RouteRecordNormalized[]>('/admin/menu/getServerMenu');
}

export function queryUserList(param?: any) {
  return axios.post('/admin/user', param);
}

export function createUser(param?: UserState) {
  return axios.post('/admin/user/create', param);
}

export function updateUser(param?: UserState) {
  return axios.post('/admin/user/update', param);
}

export function deleteUser(param: { id?: number }) {
  return axios.post('/admin/user/delete', param);
}

export function queryRoleList(param?: any) {
  return axios.post('/admin/role', param);
}

export function createRole(param?: any) {
  return axios.post('/admin/role/create', param);
}

export function updateRole(param?: any) {
  return axios.post('/admin/role/update', param);
}

export function deleteRole(param: { id?: number }) {
  return axios.post('/admin/role/delete', param);
}

